<template>
  <div class="storeUserModify common-container">
    <div class="common-top">
      <span class="left">
        <span class="go-back" @click.stop="$router.go(-1)">返回</span>
      </span>
      <el-button type="primary" @click="save">保存</el-button>
    </div>
    <div class="common-bot">
      <div class="modify-bot">
        <el-form :model="form" label-width="auto">
          <el-form-item required label="名称" style="width: 50%">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item required label="原价格" style="width: 50%">
            <el-input v-model="form.originalPrice"></el-input>
          </el-form-item>
          <el-form-item required label="价格" style="width: 50%">
            <el-input v-model="form.price"></el-input>
          </el-form-item>
          <el-form-item required label="最大员工数量" style="width: 50%">
            <el-input v-model="form.setting.maxEmployee"></el-input>
          </el-form-item>
          <el-form-item required label="最大门店数量" style="width: 50%">
            <el-input v-model="form.setting.maxStore"></el-input>
          </el-form-item>
          <el-form-item required label="最大连锁数量" style="width: 50%">
            <el-input v-model="form.setting.maxStoreChain"></el-input>
          </el-form-item>
          <el-form-item required label="最大仓库数量" style="width: 50%">
            <el-input v-model="form.setting.maxWarehouse"></el-input>
          </el-form-item>
          <el-form-item required label="排序" style="width: 30%">
            <el-input v-model="form.queue"></el-input>
          </el-form-item>
          <el-form-item label="是否为新人默认级别" style="width: 30%">
            <el-switch v-model="form.defForNewer"></el-switch>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import UploadFile from "@/components/uploadFile";
import {
  provinceAndCityData,
  CodeToText,
  TextToCode,
} from "element-china-area-data";
import ManaApi from "@/api/index";
export default {
  name: "storeUserModify",
  components: { UploadFile },
  data() {
    return {
      areaSelectData: provinceAndCityData,
      genderOptions: [
        {
          label: "男",
          value: "male",
        },
        {
          label: "女",
          value: "female",
        },
      ],
      vipOptions: [
        {
          label: "普通版",
          value: "0",
        },
      ],
      form: {
        defForNewer: true,
        formId: 0,
        name: "",
        queue: 0,
        originalPrice:0,
        price:0,
        setting: {
          ingredientEnable: true,
          maxEmployee: 0,
          maxStore: 0,
          maxStoreChain: 0,
          maxWarehouse: 0,
        },
      },
      roleOptions: [
        {
          label: "老板",
          value: "boss",
        },
        {
          label: "员工",
          value: "employee",
        },
      ],
    };
  },
  methods: {
    uploadSuc(data) {
      this.$set(this.form, "avatar", data.url);
      console.log(data);
    },
    save() {
      if (!this.checkInfo()) {
        return;
      }
      let form = JSON.parse(JSON.stringify(this.form));
      form.originalPrice = this.$bigNumber("times",form.originalPrice,100);
      form.price = this.$bigNumber("times",form.price,100);
      ManaApi.vip.edit(form).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.$router.go(-1);
        }
      });
    },
    checkInfo() {
      if (String(this.form.name).trim() == "") {
        this.$message.error("请填写名称");
        return false;
      }
      return true;
    },
    getInfo() {
      ManaApi.vip
        .detail({
          targetId: this.$route.query.id,
        })
        .then((res) => {
          this.form = {
            name: res.data.name,
            defForNewer: res.data.defForNewer,
            formId: res.data.id,
            queue: res.data.queue,
            originalPrice:this.$bigNumber("div",res.data.originalPrice,100),
            price:this.$bigNumber("div",res.data.price,100),
            setting: {
              ingredientEnable: res.data.setting.ingredientEnable,
              maxEmployee: res.data.setting.maxEmployee,
              maxStore: res.data.setting.maxStore,
              maxStoreChain: res.data.setting.maxStoreChain,
              maxWarehouse: res.data.setting.maxWarehouse,
            },
          };
        });
    },
  },
  mounted() {
    if (this.$route.query.type == "edit") {
      this.getInfo();
    }
  },
};
</script>
<style lang="scss" scoped>
.storeUserModify {
}
</style>